from enum import Enum
from typing import List
from .basics_model import *
from .base import BaseModel
import dataclasses

from .baidu import BaiduFaceDetect


class PhotoStandardMode(str, Enum):
    STRICT = "STRICT"
    AUTO = "AUTO"


class PhotoStandardWarning(BaseModel):
    code: str
    msg: str


class PhotoStandardConfig(BaseModel):
    # 模式
    mode: PhotoStandardMode = PhotoStandardMode.STRICT
    # 是否检查图片符合要求，如果设置为False，则表示不检查图片，图片检车是写死通过
    check: bool = True
    # 人像偏转最大值
    face_min_width: int = 185
    # 人像偏转最大值
    head_top_min_width: int = 0
    # 头顶位置
    overhead_position: float = 0.11
    # 脸长比例
    face_length_ratio: float = 0.53
    # 脸长比例计算幅度
    face_length_ratio_step: float = 0.001
    # 脸长比例范围
    face_length_ratio_range: List[float] = dataclasses.field(
        default_factory=lambda: [0.53, 0.64]
    )
    # 脸宽比例范围
    face_width_ratio_range: List[float] = dataclasses.field(
        default_factory=lambda: [0.38, 0.62]
    )
    # dpi
    dpi: int = 300
    # 照片宽高比
    photo_ratio: float = 0.75
    # 照片背景
    background_color: str = "#00A3E6"
    change_background_color: bool = True
    # 人像偏转最大值
    face_ratio_max: float = 10
    # 压缩目标
    compression_size: List[int] = dataclasses.field(default_factory=lambda: [480, 640])
    # 眼睛判断置信度
    eye_status: float = 0.6
    # 眼镜判断置信度
    glasses_probability: float = 0.9
    # 口罩判断置信度
    mask_probability: float = 0.95
    # 人脸各部位遮挡概率判断
    face_quality: dict[str, float] = dataclasses.field(
        default_factory=lambda: {
            "left_eye": 0.6,
            "right_eye": 0.6,
            "nose": 0.7,
            "mouth": 0.7,
            "left_cheek": 0.8,
            "right_cheek": 0.8,
            "chin_contour": 0.6,
        }
    )
    # 人脸模糊判断
    face_blur: float = 0.7
    # 人脸融合判断值
    face_spoofing: float = 0.00547


# 照片标准化细节参数传参实体
class PhotoStandardOptionsModel:
    top: float  # 头顶位置
    face_location: Rectangle  # 人脸矩形框
    face_top: Point  # 人脸顶部位置
    chin_position: Point  # 下巴位置
    cheek_left: Point  # 左脸颊位置
    cheek_right: Point  # 右脸颊位置
    nose_tip: Point  # 鼻尖位置
    rotation: int  # 人脸框相对于竖直方向的顺时针旋转角[-180,180]


# 照片标准化传参实体
class PhotoStandardModel:
    image_base64: str  # 人像抠图
    top: float
    options: BaiduFaceDetect  # 参数
